﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using mobil_lab1.localhost;

namespace mobil_lab1
{
    public partial class ElementForm : Form
    {
        private bool isNew;
        private localhost.MusicWebService mWs = new MusicWebService();
        private Element node, parent;
        

        public ElementForm(Element parent, Element node)
        {
            isNew = false;
            InitializeComponent();
            this.node = node;
            
            txbDesc.Text = node.Text;
            txbTitle.Text = node.Title;
            lblParentTitle.Text = parent.Title;

        }

        public ElementForm(Element parent)
        {
            isNew = true;
            this.parent = parent;
            this.node = new Element();
            InitializeComponent();
            lblParentTitle.Text = parent.Title;
            
            

        }

        private void menuSave_Click(object sender, EventArgs e)
        {
            node.Text = txbDesc.Text;
            node.Title = txbTitle.Text;
            if (isNew)
                mWs.Add(node, parent);
            else
                mWs.Modify(node);
            Dispose();
        }

        private void menuCancel_Click(object sender, EventArgs e)
        {
            Dispose();
        }

    }
}